<?php

// Register Custom Navigation Walker
require_once('wp_bootstrap_navwalker.php');

// Load Js File
if (!is_admin())
    add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);

function my_jquery_enqueue() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null);
    wp_enqueue_script('jquery');
    wp_enqueue_script('comment-reply');
}

//Insert main.js
function main_javascript() {
    wp_enqueue_script('mainjs', get_stylesheet_directory_uri() . '/js/main.js', array('jquery'));
}

add_action('wp_enqueue_scripts', 'main_javascript');

// Create Custom Boostraps Menu
register_nav_menus(array(
    'primary' => __('Primary', 'hongthang'),
));
// create side bar
if (function_exists('register_sidebar')) {
    register_sidebar(array(
        'name' => 'Sidebar Chính',
        'id' => 'sidebar-right',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
        'after_widget' => '</div>',
        'before_title' => '<h4 class="widget-title" style="display: none;">',
        'after_title' => '</h4>'
    ));
}

// Add set Feature image
add_theme_support('post-thumbnails');
//Tạo widget danh sách bài mới
require_once('widget/news.php');
// Yahoo support Widget
require_once('widget/support.php');
// Reservation widget
require_once('widget/reservation.php');
// Turn off notification update Wordpress Version
add_action('admin_menu', 'wphidenag');

function wphidenag() {
    remove_action('admin_notices', 'update_nag', 3);
}

add_filter ('pre_site_transient_update_core',create_function ('$a', "return null;"));
// Custom Single Post by Category
add_filter('single_template', 'check_for_category_single_template');
function check_for_category_single_template( $t )
{
  foreach( (array) get_the_category() as $cat ) 
  { 
    if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php"; 
    if($cat->parent)
    {
      $cat = get_the_category_by_ID( $cat->parent );
      if ( file_exists(TEMPLATEPATH . "/single-category-{$cat->slug}.php") ) return TEMPLATEPATH . "/single-category-{$cat->slug}.php";
    }
  } 
  return $t;
}

// Turn off notification Plugin update
remove_action ('load-update-core.php', 'wp_update_plugins');
add_filter ('pre_site_transient_update_plugins',create_function ('$a', "return null;"));

// Turn off notification Theme update
remove_action ('load-update-core.php', 'wp_update_themes');
add_filter ('pre_site_transient_update_themes',create_function ('$a', "return null;"));
